﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace UI.View.Repairs.Part
{
    /// <summary>
    /// SelectRoom.xaml 的交互逻辑
    /// </summary>
    public partial class SelectRoomView : UserControl
    {
        Model.DataContext context = new Model.DataContext();
        public SelectRoomView()
        {
            InitializeComponent();

           
           var builList = context.DB.Queryable<Model.Building>().ToList();

            cmb_build.ItemsSource = builList;
            cmb_build.SelectedValuePath = "Id";
            cmb_build.DisplayMemberPath = "Name";
        }

        private void cmb_room_DropDownOpened(object sender, EventArgs e)
        {
            if(cmb_build.SelectedValue!=null)
            {
                int bid = (int)(cmb_build.SelectedValue);
                var roomList = context.DB.Queryable<Model.Rooms>().Where(r => r.BuildingId == bid).ToList();

                cmb_room.ItemsSource = roomList;
                cmb_room.SelectedValuePath = "Id";
                cmb_room.DisplayMemberPath = "No";


            }
            
        }

        public Model.Rooms SelectRoom { get; set; }

        private void cmb_room_DropDownClosed(object sender, EventArgs e)
        {
            if(cmb_room.SelectedItem!=null)
            {
                SelectRoom = (Model.Rooms)cmb_room.SelectedItem;
            }
        }
    }
}
